/**
 * 
 */
package net.smartlab.android.callmanager.listeners;

import net.smartlab.android.callmanager.services.MusicService;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

/**
 * @author placava
 * 
 */
public class CallStateListener extends PhoneStateListener {
	
	/**
	 * 
	 */
	private Context context;
	public CallStateListener(Context context) {
		super();
		this.context =  context;
	}

	public void onCallStateChanged(int state, String incomingNumber) {
		switch (state) {
		case TelephonyManager.CALL_STATE_IDLE:
			Log.d("DEBUG", "IDLE "+incomingNumber);
			Toast.makeText(context, "Phone state IDLE", Toast.LENGTH_LONG).show();
			break;
		case TelephonyManager.CALL_STATE_OFFHOOK:
			Log.d("DEBUG", "OFFHOOK "+incomingNumber);
			Toast.makeText(context, "Phone state OFFHOOK", Toast.LENGTH_LONG).show();
			context.stopService(new Intent(context,MusicService.class));
			break;
		case TelephonyManager.CALL_STATE_RINGING:
			Log.d("DEBUG", "RINGING "+incomingNumber);
			Toast.makeText(context, "Phone state RINGING", Toast.LENGTH_LONG).show();
			break;
		}
	}
}
